package com.hmsg.health.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.hmsg.health.bean.enums.StatusCode;
import com.hmsg.health.param.ResponseResult;
import com.hmsg.health.qiniu.QiniuUpload;
import com.hmsg.health.security.IgnoreSecurity;
import com.hmsg.health.security.OpenApi;
import com.hmsg.health.service.aes.SecurityData;
import com.hmsg.health.utils.HttpModelResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author Tareva on 2018/6/14.
 * @Description TODO
 */
@Api(value = "七牛", tags = { "七牛" })
@Controller
@RestController
@RequestMapping("/qiniu")
public class QiniuController {
	
	@Autowired
    private QiniuUpload qiniuUpload;

	@GetMapping("/qiniuToken")
	@ResponseBody
    @IgnoreSecurity
	@OpenApi
	@ApiOperation(value="七牛token", notes="七牛token" ,httpMethod="GET")
	@ApiImplicitParams({
   		@ApiImplicitParam(name="fileName", value="文件名称", dataType = "String", required=false, paramType="form")
   	})
	@SecurityData
	public  ResponseResult<Object> getUptoken(@RequestParam String fileName) throws Exception {
		 Map<String, String> map = new HashMap<String, String>();
	        map.put("imgUrl", QiniuUpload.HOST_MIANAO_IMG + fileName);
	        map.put("uploadToken", qiniuUpload.getMianaoImgToken());

		return new ResponseResult<Object>(StatusCode.SYSTEM_SUCCESS, map);
	}


	@GetMapping("/qiniuTokens")
	@ResponseBody
	@IgnoreSecurity
	@OpenApi
	@ApiOperation(value="七牛token", notes="七牛token" ,httpMethod="GET")
	@ApiImplicitParams({
			@ApiImplicitParam(name="fileName", value="文件名称", dataType = "String", required=false, paramType="form")
	})
	public  ResponseResult<Object> getUptokens(@RequestParam String fileName) throws Exception {
		Map<String, String> map = new HashMap<String, String>();
		map.put("imgUrl", QiniuUpload.HOST_MIANAO_IMG + fileName);
		map.put("uploadToken", qiniuUpload.getMianaoImgToken());

		return new ResponseResult<Object>(StatusCode.SYSTEM_SUCCESS, map);
	}

    

}
